package com.lyf.scm.plan.api.controller;

import com.github.pagehelper.PageInfo;
import com.lyf.scm.common.model.ExcelExportDataDTO;
import com.lyf.scm.common.util.ExcelExportUtil;
import com.lyf.scm.plan.api.dto.SalesPlanOtherDTO;
import com.lyf.scm.plan.api.dto.SalesPlanOtherDifferinInfoDTO;
import com.lyf.scm.plan.domain.service.SalesPlanOtherDifferinService;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.util.controller.RomeController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author: huangtao
 * @Description:
 * @Date: create in 2020/7/31
 */
@Slf4j
@Api(tags = "其他渠道计划_目标与销售计划差异")
@RequestMapping("/api/v1/slaesPlanOtherDifferin")
@RomeController
public class  SalesPlanOtherDifferinController {
    @Resource
    private SalesPlanOtherDifferinService salesPlanOtherDifferinService;

    @PostMapping("/listWeek")
    @ApiOperation(value = "按条件查询其他渠道计划_目标与销售计划差异(周)")
    public Response<PageInfo<SalesPlanOtherDifferinInfoDTO>> listWeekBySelective(@RequestBody SalesPlanOtherDTO salesPlanOtherDTO) {
        return Response.builderSuccess(salesPlanOtherDifferinService.listWeekBySelective(salesPlanOtherDTO));
    }

    @PostMapping("/listAllByCycles")
    @ApiOperation(value = "查询全渠道其他渠道计划_目标与销售计划差异(范围)")
    public Response<List<SalesPlanOtherDifferinInfoDTO>> listAllByCycles(@RequestBody SalesPlanOtherDTO salesPlanOtherDTO) {
        return Response.builderSuccess(salesPlanOtherDifferinService.listAllByCycles(salesPlanOtherDTO));
    }

    @PostMapping("/export")
    @ApiOperation(value = "导出")
    public void export(@RequestBody SalesPlanOtherDTO salesPlanOtherDTO, @RequestParam Integer type, HttpServletResponse httpServletResponse) {
        try {
            ExcelExportDataDTO excelExportDataDTO = salesPlanOtherDifferinService.export(salesPlanOtherDTO, type);
            ExcelExportUtil.exportExcel(httpServletResponse, excelExportDataDTO);
        } catch (Exception e) {
            ExcelExportUtil.handleExceptionResponse(httpServletResponse, e);
        }
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除对应标识数据")
    public Response delete(@RequestParam("opSign") String opSign) {
        salesPlanOtherDifferinService.delete(opSign);
        return Response.builderSuccess(null);
    }
}
